/**
 * Created by master on 2016/7/15.
 */
var TimeUtil;
TimeUtil = {
    /**
     * @function 将时间戳转化为日+小时+分+秒
     * @param time 时间戳
     * @param format 格式
     * @return 时间字符串
     */
    format: function(time,format) {
        var t = new Date(time);
        var tf = function (i) { return (i < 10 ? '0' : '') + i };
        var str = format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
            switch (a) {
                case 'yyyy':
                    return tf(t.getFullYear());
                    break;
                case 'MM':
                    return tf(t.getMonth() + 1);
                    break;
                case 'mm':
                    return tf(t.getMinutes());
                    break;
                case 'dd':
                    return tf(t.getDate());
                    break;
                case 'HH':
                    return tf(t.getHours());
                    break;
                case 'ss':
                    return tf(t.getSeconds());
                    break;
            }
        })

        return str.replace(/\'/g,"");
    },
    yyyyMMdd:function(time){
        return this.format(time,'yyyy-MM-dd');
    },
    yyyyMMddHHmmss:function(time){
        return this.format(time,"'yyyy-MM-dd HH:mm:ss'");
    }
};